package com.yunhe.abnormal.service.base.impl;

import com.yunhe.abnormal.domain.base.AlarmScope;
import com.yunhe.abnormal.mapper.base.AlarmScopeMapper;
import com.yunhe.common.model.base.AlarmScopeDTO;
import com.yunhe.abnormal.repository.base.AlarmScopeRepository;
import com.yunhe.abnormal.service.base.AlarmScopeService;
import com.yunhe.common.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 异常适用范围Service
 * @author liuronglei
 */
@Service
public class AlarmScopeServiceImpl implements AlarmScopeService {
    @Autowired
    private AlarmScopeRepository alarmScopeRepository;
    @Autowired
    private AlarmScopeMapper alarmScopeMapper;

    /**
     * 根据ID获得异常适用范围对象
     * @param id 状态ID
     */
    public AlarmScopeDTO findById(Long id) {
        AlarmScope result = alarmScopeRepository.findById(id).orElse(null);
        return alarmScopeMapper.to(result);
    }

    /**
     * 根据编号获得异常适用范围对象
     * @param name 编号
     */
    public AlarmScopeDTO findByName(String name) {
        AlarmScope result = alarmScopeRepository.findByName(name);
        return alarmScopeMapper.to(result);
    }

    /**
     * 获得全部异常适用范围对象
     */
    public Iterable<AlarmScopeDTO> findAll() {
        List<AlarmScope> results = (List<AlarmScope>) alarmScopeRepository.findAll(QueryUtil.defaultSort());
        return alarmScopeMapper.to(results);
    }

}
